package com.mytest.test.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @description:
 * @author: chengxucai
 * @createDate: 2022/2/17
 */
@EnableSwagger2
@Configuration
@EnableKnife4j
public class SwaggerConfig {
    //是否开启swagger，生产或线上环境一般设置为false
    //@Value("${swagger.enabled}")
    private boolean enableSwagger=true;

    @Bean
    public Docket group1x() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enableSwagger)
                //分组名称
                .groupName("我的测试")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.mytest.test.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("接口文档")
                .version("1.0")
                .termsOfServiceUrl("localhost")
                .license("license")
                .licenseUrl("licenseUrl")
                .build();


    }
}
